﻿using Kingdee.BOS.Orm.DataEntity;
using SD.WRZS.K3.ServiceFacade.KDServiceEntity.Mobile;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SDWXServer.Models
{
    /// <summary>
    /// 仓库
    /// </summary>
    [Serializable]
    public class WXStock : AbstractBillObject
    {
        public WXStock()
        {
            Organization = new Organization();
        }
        /// <summary>
        /// Id
        /// </summary>
        public string Id { get; set; }
        /// <summary>
        /// AppId
        /// </summary>
        public string AppId { get; set; }
        /// <summary>
        /// 内码
        /// </summary>
        public Int64 BillId { get; set; }
        /// <summary>
        /// 单据编码
        /// </summary>
        public string BillNO { get; set; }
        /// <summary>
        /// 单据状态
        /// </summary>
        public string DocumentStatus { get; set; }
        /// <summary>
        /// 单据状态名称
        /// </summary>
        public string DocumentStatusName { get; set; }
        /// <summary>
        /// 组织
        /// </summary>
        public Organization Organization { get; set; }
        /// <summary>
        /// 仓库名称
        /// </summary>
        public string StockName { get; set; }
        public static WXStock Parse(DynamicObject obj)
        {
            var item = new WXStock();
            item.Id = string.Format("SZGD_Stock_{0}", Convert.ToInt64(obj["Id"]));
            item.AppId = string.Format("SZGD_Stock_{0}", Convert.ToInt64(obj["Id"]));
            item.BillId = Convert.ToInt64(obj["Id"]);
            item.BillNO = Convert.ToString(obj["Number"]);
            //item.BillDate = Convert.ToDateTime(obj["Date"]);
            item.DocumentStatus = Convert.ToString(obj["DocumentStatus"]);
            switch (item.DocumentStatus)
            {
                case "Z":
                    item.DocumentStatusName = "暂存";
                    break;
                case "A":
                    item.DocumentStatusName = "创建";
                    break;
                case "B":
                    item.DocumentStatusName = "审核中";
                    break;
                case "C":
                    item.DocumentStatusName = "已审核";
                    break;
                case "D":
                    item.DocumentStatusName = "重新审核";
                    break;
            }
            var orgObj = obj["UseOrgId"] as DynamicObject;
            item.Organization.Id = Convert.ToInt64(orgObj["Id"]);
            item.Organization.Number = Convert.ToString(orgObj["Number"]);
            item.Organization.Name = Convert.ToString(orgObj["Name"]);
            item.StockName = Convert.ToString(obj["Name"]);

            return item;
        }
    }
}